package com.itheima.object;

import java.io.*;
import java.util.ArrayList;

public class IODemo02 {
    public static void main(String[] args) throws Exception {
        //writeObject();
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("a.txt"));
       ArrayList<User> list2=(ArrayList<User>)ois.readObject();
       ois.close();
        for (User user : list2) {
            System.out.println(user);
        }
    }

    private static void writeObject() throws IOException {
        User user1=new User("张三",18);
        User user2=new User("李四",16);
        User user3=new User("王五",22);

        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("a.txt"));
        ArrayList<User> list=new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);
        oos.writeObject(list);
        oos.close();
    }
}
